/*
 * @Description: 
 * @Version: 2.0
 * @Autor: ftt
 * @Date: 2022-06-14 14:19:47
 * @LastEditors: TT
 * @LastEditTime: 2022-07-11 16:47:29
 */

import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:hzy_normal_widget/hzy_normal_widget.dart';
import 'package:hzy_template/config/dataconfig/language_info_config.dart';
import '../../../components/common_index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../config/config_index.dart';
import '../controllers/home_list_c.dart';
import '../routers/home_page_id.dart';

class HomeListV extends CommonGetXlistWidget<HomeListC> {
  HomeListV({Key? key}) : super(key: key);
  @override
  Color? get backgroundColor => HzyColorConfig().whitebackgroundColor;
  @override
  HomeListC get controller => Get.put(HomeListC());
  @override
  String? get title => LauchNormalMsg.hometitle;
  @override
  bool get safeAreabottm => false;
  @override
  Widget createBody(BuildContext context) {
    return Stack(
      children: [
        Padding(
          padding: EdgeInsets.only(left: 15.w, right: 15.w, top: 15.w),
          child: createRefreshWidget(context),
        )
      ],
    );
  }

  @override
  List<Widget>? createAppBaractions() {
    return [
      Obx(
        () => controller.pageState.value == PageState.emptyDataState
            ? Container()
            : InkWell(
                child: SizedBox(
                  width: 54.w,
                  height: 54.w,
                  child: Obx(
                    () => Icon(
                      controller.multiple.value
                          ? Icons.dashboard
                          : Icons.view_agenda,
                      color: HzyColorConfig().col000000,
                    ),
                  ),
                ),
                onTap: () {
                  controller.changeItemW();
                },
              ),
      )
    ];
  }

  @override
  Widget createListView(BuildContext context) {
    return MasonryGridView.count(
      crossAxisCount: !controller.multiple.value ? 1 : 2,
      itemBuilder: (BuildContext context, int index) {
        return createListitem(context, index);
      },
      itemCount: controller.list.length,
      crossAxisSpacing: 15.w,
      mainAxisSpacing: 15.w,
    );
  }

  @override
  Widget createListitem(BuildContext context, int index) {
    String heroStr = "HERO + $index";
    return InkWell(
      onTap: () {
        currentToPage(HomePageId.homedetail, arguments: heroStr);
      },
      child: Hero(
        tag: heroStr,
        child: createitemWidget(),
      ),
    );
  }

  /// 创建文章item
  Widget createitemWidget() {
    double itemh = controller.itemw.value * 4 / 3;
    return Container(
      width: controller.itemw.value,
      height: itemh,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(
          Radius.circular(
            15.r,
          ),
        ),
        color: HzyColorConfig().colefedf3,
      ),
    );
  }
}
